//保存表格的实例对象
var sx = null;
//调用封装方法
getTable();

// ---------------------------------------------------
//方法区

//封装方法重载表格
function sxTable(){
    //通过表格id参数  重载刷新
    sx.reload()
}


//封装渲染表格
function getTable(){
    layui.use(['table','layer','jquery','form','laydate'],function() {
        //模板保存到变量上
        var laydate = layui.laydate;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.$;

        //监听顶部刷新按钮
        form.on('submit(sx)',function (d){
            location.reload();
        })

        //鉴定顶部返回按钮
        form.on('submit(fh)',function (d){
            layer.msg('返回上一级页面')
        })


        //监听顶部搜索按钮
        form.on('submit(*)',function (d){
            console.log(d.field)
            var data = d.field;
            sx.reload({
                url:'/YltUser/AuditManage/getTurnListByLike',
                where:{
                    userName:data.userName,
                    userAccount:data.userAccount,
                    auditTime:data.auditTime
                }
            },true)
            return false
        })

        //监听顶部重置按钮
        form.on('submit(cz)',function (d){
            $("[name=userName]").val(undefined)
            $("[name=userAccount]").val(undefined)
            $("[name=auditTime]").val(undefined)

            sx.reload({
                url:'/YltUser/AuditManage/getTurnList',
            },true)
            return false
        })

        // 渲染input日期
        laydate.render({
            elem:'#auditTime'
        })

        sx = table.render({
            elem:"#demo",
            url:"/YltUser/AuditManage/getTurnList",
            page:{
                layout:['count','prev','page','next','limit'],
                groups:5,
                limit:10,
                limits:[5,10,20]
            },
            cols:
                [[
                    // {field: 'turnId', title: '序号',width: 100,align: 'center'},
                    {field: 'userId', title: '用户编号',width: 100,align: 'center'},
                    {field: 'userAccount', title: '用户账号', width:150,align: 'center'},
                    {field: 'userName', title: '用户昵称',width: 150,align: 'center'},
                    {field: 'applyJob', title: '申请职位', width:150,align: 'center'},
                    {field: 'auditTime', title: '申请时间', width: 200,align: 'center'},
                    {field: 'turnRemark', title: '驳回原因', width: 200,align: 'center'},
                    {field: 'turnTime', title: '驳回时间', width: 200,align: 'center'}
                ]],
            toolbar:'#toolbardemo',
            skin: 'line',
            parseData:function (res){
                return{
                    "code":res.code,
                    "msg":res.msg,
                    "count":res.count,
                    "data":res.data
                }
            }
        })
    })
}



